home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Inside Mac Games Volume 5 #3
/
IMG 46 Vol 5-3.iso
/
More Goodies
/
More For Your Game
/
Realmz
/
Character Master Source
/
Character Master
/
my AppleEvents.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1996-07-16
|
3KB
|
125 lines
#include "my AppleEvents.h"
#include "character class.h"
#include "my menus.h"
#include "main.h"
#include "my files.h"
pascal OSErr HandleOAppAE(AppleEvent *theAEvent, AppleEvent *theReply, long refCon)
{
// Not much to this one 'cos we don't really do much when we open.
return noErr;
}
pascal OSErr HandleQuitAE(AppleEvent *theAEvent, AppleEvent *theReply, long refCon)
{
// Just act as if the user chose quit from the menu.
OSErr error = noErr;
error = DoQuitMChoice();
return error;
}
pascal OSErr HandleODocAE(AppleEvent *theAEvent, AppleEvent *theReply, long refCon)
{
OSErr error = noErr, firstError = noErr;
short numErrors = 0;
AEDesc theList;
long numFiles, fileCount;
// the direct object parameter is the list of aliases to files (one or more)
error = AEGetParamDesc(theAEvent, keyDirectObject, typeAEList, &theList);
if (error) return error;
// that should be all, but in case something is screwy...
error = HasUnusedParameters(theAEvent);
if (error) return error;
// get number of files in list
error = AECountItems(&theList, &numFiles);
if (error) return error;
// Check we know where Realmz is. If we don't we can't open characters
if( !CMData()->KnowWhereRealmzIs() )
DoLocateRealmz();
if( !CMData()->KnowWhereRealmzIs() )
return error;
FSSpec fileToOpen;
long actualSize;
AEKeyword dummyKeyword;
DescType dummyType;
// open each file - keep track of errors
for (fileCount = 1; fileCount <= numFiles; fileCount++)
{
// get the alias for the nth file, convert to an FSSpec
error = AEGetNthPtr(&theList, fileCount, typeFSS, &dummyKeyword, &dummyType,
(Ptr) &fileToOpen, sizeof(FSSpec), &actualSize);
if (error) return error;
if( IsOpenableFile( fileToOpen ) )
{
// open the file
error = DoOpen( fileToOpen );
// count file opening errors
if (error)
{
++numErrors; // keep count
if (numErrors == 1)
firstError = error; // save first error
}
} // Otherwise just ignore it. Probably the prefs file
}
// set proper error message
if (numErrors) // at least one happend
{
if (numErrors > 1) // had more than one
{
error = kMultipleOpenError;
}
else
{
error = firstError;
}
}
AEDisposeDesc(&theList); // dispose what we allocated
return error;
}
pascal OSErr HandlePDocAE(AppleEvent *theAEvent, AppleEvent *theReply, long refCon)
{
// This function disnae dae much as a cannae print
return noErr;
}
OSErr HasUnusedParameters(AppleEvent *theAEvent)
{
OSErr error;
long actualSize;
DescType dummyType;
AEKeyword missedKeyword;
// Get the "missed keyword" attribute from the AppleEvent.
error = AEGetAttributePtr(theAEvent, keyMissedKeywordAttr, typeKeyword, &dummyType,
(Ptr)&missedKeyword, sizeof(missedKeyword), &actualSize);
// If the descriptor isn't found, then we got the required parameters.
if (error == errAEDescNotFound)
{
error = noErr;
}
else
{
error = errAEEventNotHandled;
}
return error;
}